<layout name='Layout/layout_main' />
<link type="text/css" href="__PUBLIC__/css/jquery-ui.css" rel="stylesheet"/>
<script type="text/javascript" src="__PUBLIC__/js/jquery-ui.min.js"></script>
<script type="text/javascript">
	function save() {
		if(check_form("form_data")){
			sendForm("form_data", "{:U('save')}","__URL__");
		}
	}

	$(document).ready(function() {
		
		$("#po_date").datepicker();
		$(".qty input,.price input").live("blur",function(){
			qty=$(this).parents("div.span6").find(".qty input").val();
			price=$(this).parents("div.span6").find(".price input").val();
			$(this).parents("div.span6").find(".sum input").val(dec_mul(price,qty));
		});
		$(".sum input").live("blur", function() {
			qty = $(this).parents("div.span6").find(".qty input").val();
			sum = $(this).parents("div.span6").find(".sum input").val();
			$(this).parents("div.span6").find(".price input").val(Math.round(dec_div(sum, qty) * 100) / 100);
		})
		$(".qty input,.price input").live("keyup",function(){
			switch(event.keyCode)
			{
				case 13:
					qty=$(this).parents("div.span6").find(".qty input").val();
					price=$(this).parents("div.span6").find(".price input").val();
					$(this).parents("div.span6").find(".sum input").val(dec_mul(price,qty));
				 break	
			}
		})			
		$(".sum input").live("keyup",function(){
			switch(event.keyCode)
			{
				case 13:
					qty=$(this).parents("div.span6").find(".qty input").val();
					sum=$(this).parents("div.span6").find(".sum input").val();
					$(this).parents("div.span6").find(".price input").val(Math.round(dec_div(sum,qty)*100)/100);
				 break	
			}
		})
			
	})

	function select_supplier() {
		winopen("{:U('supplier/winpop')}", 600, 400);
	}

	function process(obj,data){		
		li=obj.parents("li.tbody");
		li.find(".name").text(data.name);
		li.find(".spec").text(data.spec);
		li.find(".unit").text(data.unit);
		li.find("input[name='mat_no[]']").val(data.mat_no);		
		li.find("input[name='price[]']").val(data.buy_price);		
	}

	function new_line(){
		new2=$("#sample").html();
		$(".table ul.po_item").append(new2);
	}

	function del_line(){
		$("input[name='po_item_id[]']:checked").parents("li").remove();	
		$("form #chk_select_all").attr("checked",false);
	}
</script>
<div class="po">
	<div class="row-fluid title">
		<span>新建：采购订单</span>
	</div>
	<div class="row-fluid operate">
		<div class="left">
			<a class="btn" onclick="new_line();" >新行</a>
			<a class="btn" onclick="del_line();" >删行</a>
			<a class="btn" onclick="send(true);">打印</a>
			<a class="btn" onclick="send(true);">取消</a>
		</div>
		<div class="right">
			<a class="btn" onclick="save();" >保存</a>
			<a class="btn" onclick="edit();">修改</a>
			<a class="btn" onclick="new_order();">新单</a>
			<a class="btn" onclick="save();" >关闭</a>
		</div>
	</div>
	<form method='post' id="form_data" name="form_data" enctype="multipart/form-data">
		<input type="hidden" id="ajax" name="ajax" value="0">
		<input type="hidden" id="add_file" name="add_file">
		<input type="hidden" id="opmode" name="opmode" value="add">
		<div class="form_box">
			<div class="row-fluid form-horizontal">
				<div class="control-group span6">
					<label class="control-label" for="supplier_name">供应商：</label>
					<div class="controls">
						<div class="input-append">
							<input  type="text" id="supplier_name" name="supplier_name" class="val"  source="{:U('supplier/json')}" check="require" msg="请输入供应商">
							<input  type="hidden" id="supplier" name="supplier" class="key" check="require" msg="请输入供应商">
							<button class="btn" type="button"  onclick="select_supplier()" >选择</button>
						</div>
						<div class="search dropdown ">
							<ul class="dropdown-menu"></ul>
						</div>
					</div>
				</div>
				<div class="control-group span6">
					<label class="control-label" for="">日期：</label>
					<div class="controls">
						<input type="text" name="po_date" id="po_date" value="{:toDate(time(),'Y-m-d')}"></div>
				</div>
			</div>
			<div class="row-fluid form-horizontal">
				<div class="control-group span6">
					<label class="control-label" for="type">订单类型：</label>
					<div class="controls">
						<select name="type">
							<option value="1">采购订单</option>
							<option value="2">直接入库</option>
						</select>
					</div>
				</div>
				<div class="control-group span6">
					<label class="control-label" for="warehouse">收货仓库：</label>
					<div class="controls">
						<select name="warehouse">
							<option value="1">一号仓库</option>
							<option value="2">二号仓库</option>
							<option value="3">三号仓库</option>
						</select>
					</div>
				</div>				
			</div>
			<div class="row-fluid form-horizontal">
				<div class="control-group span6">
					<label class="control-label" for="payment">付款方式：</label>
					<div class="controls">
						<select name="payment">
							<option value="1">预付货款</option>
							<option value="2">预付部分</option>
							<option value="3">货到付款</option>
						</select>
					</div>
				</div>
				<div class="control-group span6">
					<label class="control-label" for="prepay">预付金额：</label>
					<div class="controls">
						<input type="text" name="prepay" id="prepay" value=""></div>
				</div>
			</div>					
			<div class="table">
				<ul class="po_item">
					<li class="thead row-fluid">
						<div class="span6" style="padding-left:30px;">
							<span  class="checkbox" >
								<input type="checkbox" id="chk_select_all" value="all" onclick="select_all('po_item_id[]')"/>
							</span>
							<span style="width:25%;">编号</span>
							<span style="width:40%;">名称+属性</span>
							<span style="width:20%;">规格</span>
							<span style="width:15%;">单位</span>
						</div>
						<div class="span6">
							<span style="width:20%;" >数量</span>
							<span style="width:20%;" >进价</span>
							<span style="width:20%;" >金额</span>
							<span style="width:40%;" >备注</span>
						</div>
					</li>
					<li class="tbody row-fluid">
						<div class="span6" style="padding-left:30px;">
							<span class="checkbox">
								<input type="checkbox" name="po_item_id[]" >
							</span>
							<span style="width:25%;" >
								<span class="controls wrap">
									<input type="text" name="mat_no[]" source="{:U('material/json')}" process="process" class="val" check="require" msg="请输入资材编号">
									<div class="search dropdown">
										<ul class="dropdown-menu"></ul>
									</div>
								</span>
							</span>
							<span style="width:40%;" class="name autocut">&nbsp;</span>
							<span style="width:20%;" class="spec text-center">&nbsp;</span>
							<span style="width:15%;" class="unit text-center">&nbsp;</span>
						</div>
						<div class="span6">
							<span style="width:20%;"  class="qty controls">
								<input type="text" name="qty[]" class="text-right" check="number" msg="必须是数字"></span>
							<span style="width:20%;"  class="price controls">
								<input type="text" name="price[]" class="text-right" check="number" msg="必须是数字"></span>
							<span style="width:20%;"  class="sum controls">
								<input type="text" name="sum[]" class="text-right" check="number" msg="必须是数字"></span>
							<span style="width:40%;" class="remark controls" >
								<input type="text" name="remark[]" class="text-right"></span>
						</div>
					</li>
				</ul>
			</div>
			<div class="row-fluid form-horizontal">
				<div class="control-group span12">
					<label class="control-label" for="name">附件：</label>
					<div class="controls">
						<div>
							<include file="Layout:uploader" />
						</div>
					</div>
				</div>
			</div>
			<div class="row-fluid form-horizontal">
				<div class="control-group span12">
					<label class="control-label" for="remark">备注：</label>
					<div class="controls">
						<input type="text" name="remark" id="remark" class="span12"></div>
				</div>
			</div>
		</div>
	</form>
	<div id="sample">
					<li class="tbody row-fluid">
						<div class="span6" style="padding-left:30px;">
							<span class="checkbox">
								<input type="checkbox" name="po_item_id[]" >
							</span>
							<span style="width:25%;" >
								<span class="controls wrap">
									<input type="text" name="mat_no[]" source="{:U('material/json')}" process="process" class="val" check="require" msg="请输入资材编号">
									<div class="search dropdown">
										<ul class="dropdown-menu"></ul>
									</div>
								</span>
							</span>
							<span style="width:40%;" class="name autocut">&nbsp;</span>
							<span style="width:20%;" class="spec text-center">&nbsp;</span>
							<span style="width:15%;" class="unit text-center">&nbsp;</span>
						</div>
						<div class="span6">
							<span style="width:20%;"  class="qty controls">
								<input type="text" name="qty[]" class="text-right" check="number" msg="必须是数字"></span>
							<span style="width:20%;"  class="price controls">
								<input type="text" name="price[]" class="text-right" check="number" msg="必须是数字"></span>
							<span style="width:20%;"  class="sum controls">
								<input type="text" name="sum[]" class="text-right" check="number" msg="必须是数字"></span>
							<span style="width:40%;" class="remark controls" >
								<input type="text" name="remark[]" class="text-right"></span>
						</div>
					</li>
	</div>
</div>